<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controlleradmin library
jimport('joomla.application.component.controlleradmin');
 
/**
 * Layouts Controller
 */
class MariagePlannerControllerLayouts extends JControllerAdmin
{
	public function __construct($config = array())
	{
		parent::__construct($config);
	
		$this->text_prefix .= "_LAYOUTS";
	}
	
	/**
	 * Proxy for getModel.
	 * @since	2.5
	 */
	public function getModel($name = 'Layout', $prefix = 'MariagePlannerModel') 
	{
		$model = parent::getModel($name, $prefix, array('ignore_request' => false));
		return $model;
	}
	
	public function save()
	{
		// Check for request forgeries
		JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
	
		// Get items to publish from the request.
		$cids = JRequest::getVar('cid', array(), '', 'array');
		$ids = JRequest::getVar('id', array(), '', 'array');
		$titles = JRequest::getVar('title', array(), '', 'array');
	
		if (empty($cids))
		{
			JError::raiseWarning(500, JText::_($this->text_prefix . '_NO_ITEM_SELECTED'));
		}
		else
		{
			// Get the model.
			$model = $this->getModel();
	
			// Make sure the item ids are integers
			JArrayHelper::toInteger($cid);
			JArrayHelper::toInteger($id);
			
			$datas = array();
			foreach($cids as $cid) {
				$idx = array_search($cid, $ids);				
				$datas[] = array( "id"=>$ids[$idx], "title"=>$titles[$idx] );
			}	
			
			// Save the items.
			foreach($datas as $data) {
				if (!$model->save($data))
				{
					JError::raiseWarning(500, $model->getError());
				}
			}
			
			$ntext = $this->text_prefix . '_N_ITEMS_SAVED';
			$this->setMessage(JText::plural($ntext, count($cids)));
		}
		$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
	}
}
?>